// 获取轮播图容器、轮播项和指示器
var slider = document.querySelector('.bigCarousel-1');
var slides = slider.getElementsByTagName('li');
var indicators = document.querySelector('.bigCarousel-indicators').getElementsByTagName('li');

// 设置初始索引和轮播间隔时间
var currentIndex = 0;
var interval = 5000; // 3秒钟

// 自动播放函数
function autoPlay() {
  // 隐藏当前轮播项和指示器
  slides[currentIndex].style.display = 'none';
  indicators[currentIndex].classList.remove('active');
  // 更新索引
  currentIndex = (currentIndex + 1) % slides.length;
  // 显示下一个轮播项和指示器
  slides[currentIndex].style.display = 'block';
  indicators[currentIndex].classList.add('active');
}

// 启动自动播放
var timer = setInterval(autoPlay, interval);

// 鼠标悬停时停止自动播放
slider.onmouseover = function() {
  clearInterval(timer);
}

// 鼠标移出时恢复自动播放
slider.onmouseout = function() {
  timer = setInterval(autoPlay, interval);
}

// 点击指示器跳转到对应轮播项
for (var i = 0; i < indicators.length; i++) {
  indicators[i].index = i;
  indicators[i].onclick = function() {
    // 隐藏当前轮播项和指示器
    slides[currentIndex].style.display = 'none';
    indicators[currentIndex].classList.remove('active');
    // 更新索引
    currentIndex = this.index;
    // 显示对应轮播项和指示器
    slides[currentIndex].style.display = 'block';
    indicators[currentIndex].classList.add('active');
  }
}

// 点击切换按钮事件处理
document.getElementById('prevBtn').onclick = function() {
  // 隐藏当前轮播项和指示器
  slides[currentIndex].style.display = 'none';
  indicators[currentIndex].classList.remove('active');
  // 更新索引
  currentIndex = (currentIndex - 1 + slides.length) % slides.length;
  // 显示前一个轮播项和指示器
  slides[currentIndex].style.display = 'block';
  indicators[currentIndex].classList.add('active');
};

document.getElementById('nextBtn').onclick = function() {
  // 隐藏当前轮播项和指示器
  slides[currentIndex].style.display = 'none';
  indicators[currentIndex].classList.remove('active');
  // 更新索引
  currentIndex = (currentIndex + 1) % slides.length;
  // 显示下一个轮播项和指示器
  slides[currentIndex].style.display = 'block';
  indicators[currentIndex].classList.add('active');
};


